package 剑指offer.字符串;

public class 第58题翻转字符串 {

    public static String ReverseSentence(String str) {
        if (str == null || str.equals(" ") || str.equals("")) {
            return str;
        }
        String[] strArray = str.split(" ");
        StringBuilder builder = new StringBuilder();
        for (int i = strArray.length - 1; i >= 0 ; i--) {
            builder.append(strArray[i]);
            if (i != 0) {
                builder.append(" ");
            }
        }
        return builder.toString();
    }

    public static void main(String[] args) {
//        System.out.println(ReverseSentence("I am a student."));
        System.out.println(ReverseSentence(" "));
    }
}
